package com.znsd.study.service.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.znsd.entitys.Blogs_ReplyInfo;
import com.znsd.entitys.MsgInfo;
import com.znsd.entitys.Reply;
import com.znsd.entitys.SpecialtyInfo;
import com.znsd.entitys.Users;
import com.znsd.stu.dao.UserDao;
import com.znsd.study.dao.BlogsDao;
import com.znsd.study.dao.Blogs_ReplyDao;
import com.znsd.study.dao.MsgDao;
import com.znsd.study.dao.ReplyDao;
import com.znsd.study.dao.SpecialtyDao;
import com.znsd.study.service.BlogsReplyService;

@Service
public class BlogsReplyServiceImpl implements BlogsReplyService {
	
	@Autowired
	private Blogs_ReplyDao blogs_ReplyDao;
	@Autowired
	private BlogsDao blogsDao;
	@Autowired
	private UserDao userDao;
	@Autowired
	private ReplyDao replyDao;
	@Autowired
	private MsgDao msgDao;
	@Autowired
	private SpecialtyDao specialtyDao; 
	
	@Override
	public Blogs_ReplyInfo queryOne(int id) {
		return blogs_ReplyDao.queryOne(id);
	}
	@Override
	public int addReply(String blogs_id, int user_id, String context,String rid) {
		Blogs_ReplyInfo reply =new Blogs_ReplyInfo(); 
		reply.setBlogs_id(blogsDao.queryOne(Integer.parseInt(blogs_id)));
		reply.setUser_id(userDao.checkId(user_id));
		reply.setBlogs_comment(context);
		reply.setBlogs_time(new Date());
		Integer r_id=0;
		if(rid!=null) {
			r_id=Integer.parseInt(rid);
		}
		reply.setR_id(r_id);
		MsgInfo m=new MsgInfo();
		m.setMsg_context(context);
		m.setSend_user(userDao.checkId(user_id));
		m.setRecp_user(blogsDao.queryOne(Integer.parseInt(blogs_id)).getUser_id());
		msgDao.addMsg(m);
		return blogs_ReplyDao.addReply(reply);
	}
	@Override
	public List<Blogs_ReplyInfo> queryAll(int blogs_id,int page) {
		return blogs_ReplyDao.queryAll(blogs_id,page);
	}
	@Override
	public long queryCount(String blogs_id) {
		return blogs_ReplyDao.queryCount(Integer.parseInt(blogs_id));
	}
	@Override
	public int delrRply(String id) {
		int br_id=Integer.parseInt(id);
		return blogs_ReplyDao.delReply(br_id);
	}
	@Override
	public int addReply1(String br_id, Users r_user, String br_user, String context) {
		Reply reply=new Reply();
		reply.setBr_id(Integer.parseInt(br_id));
		reply.setR_users(r_user);
		reply.setBr_users(blogs_ReplyDao.queryOne(Integer.parseInt(br_user)).getUser_id());
		reply.setR_context(context);
		MsgInfo m=new MsgInfo();
		m.setMsg_context(context);
		m.setSend_user(r_user);
		m.setRecp_user(blogs_ReplyDao.queryOne(Integer.parseInt(br_user)).getUser_id());
		msgDao.addMsg(m);
		return replyDao.addReply(reply);
	}
	@Override
	public List<Reply> queryBrid(String br_id) {
		int brid=0;
		if(br_id!=null) {
			brid=Integer.parseInt(br_id);
			return replyDao.queryBrid(brid);
		}
		return null;
	}
	@Override
	public int addReply2(String br_id, Users r_user, String br_user, String context) {
		Reply reply=new Reply();
		reply.setBr_id(Integer.parseInt(br_id));
		reply.setR_users(r_user);
		reply.setBr_users(userDao.checkId(Integer.parseInt(br_user)));
		reply.setR_context(context);
		MsgInfo m=new MsgInfo();
		m.setMsg_context(context);
		m.setSend_user(r_user);
		m.setRecp_user(userDao.checkId(Integer.parseInt(br_user)));
		msgDao.addMsg(m);
		return replyDao.addReply(reply);
	}
	@Override
	public int del2(int r_id) {
		return replyDao.del2(r_id);
	}
	@Override
	public List<SpecialtyInfo> fulist() {
		return specialtyDao.fuleiList();
	}
	
	
	

}
